import axios from '@/utils/request.js'
// reqeust()调用传入请求的配置对象, 原地返回一个Promise对象

// 用户 - 登录
export const loginAPI = ({ mobile, code }) => {
  return axios({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile,
      code
    }
  })
}

// 获取列表 - 用户已选频道
export const channelListAPI = () => {
  return axios({
    url: '/v1_0/user/channels'
  })
}
// 口诀: 调用函数的地方需要结果, 就return

// 获取列表 - 所有频道
export const allChannelListAPI = () => {
  return axios({
    url: '/v1_0/channels'
  })
}

// 频道 - 更新
export const updateChannelAPI = ({ channels }) => {
  return axios({
    url: '/v1_0/user/channels',
    method: 'PUT',
    data: {
      channels: channels
    }
  })
}

// 获取 - 文章列表
export const articlesListAPI = ({ channel_id, page = 1 }) => {
  return axios({
    url: '/v1_1/articles',
    params: {
      channel_id,
      timestamp: Math.floor(new Date().getTime()),
      with_top: 1,
      page
    }
  })
}

// 文章 - 不感兴趣
export const articleDisLikeAPI = ({ target }) => {
  return axios({
    url: '/v1_0/article/dislikes',
    method: 'POST',
    data: {
      target: target
    }
  })
}

// 文章  - 举报
export const articleReportsAPI = ({ target, type }) => {
  return axios({
    url: '/v1_0/article/reports',
    method: 'POST',
    data: {
      target: target,
      type: type
    }
  })
}

// 搜索 - 联想菜单
export const suggestListAPI = ({ q }) => {
  return axios({
    url: '/v1_0/suggestion',
    params: {
      q: q
    }
  })
}

// 搜索 - 结果列表
export const SearchResultAPI = ({ q, page }) => {
  return axios({
    url: '/v1_0/search',
    params: {
      q: q,
      page: page
    }
  })
}
